import { markRaw } from 'vue'

const isLocal = location.port === '9527'

let ld
try { ld = JSON.parse(localStorage.ld) } catch { ld = {} }
ld.dbHub ??= {}
ld.dbHub.acc ??= {}
ld.dbHub.acc.list ??= []

const nav = {
  list: [
    { name: '数据库管理', com: 'com-db-hub' },
    { name: '服务器管理', com: 'com-server' },
    { name: '文件管理', com: 'com-fs' },
    { name: '算法与数据结构', com: 'com-algo' },
    { name: '家庭影院', com: 'com-cinema' },
    { name: '脑图', com: 'com-brain-graph' },
    { name: '图论', com: 'com-graph' },
    { name: '聊天室', com: 'com-chat' },
    { name: '论坛', com: 'com-forumn' },
  ],
  map: {}
}

nav.list.forEach((v) => {
  nav.map[v.com] = v
})

const keyMap = markRaw({
  13: 'enter',
  27: 'esc',
  37: 'left',
  38: 'top',
  39: 'right',
  40: 'bottom',
  ...(() => {
    const map = {}
    for (let i = 65; i < 65 + 26; i++) {
      map[i] = String.fromCharCode(i).toLowerCase()
    }
    return map
  })()
})

const color = {
  red: '#F44336',
  pink: '#E91E63',
  purple: '#9C27B0',
  deepPurple: '#673AB7',
  indigo: '#3F51B5',
  blue: '#2196F3',
  lightBlue: '#03A9F4',
  cyan: '#00BCD4',
  teal: '#009688',
  green: '#4CAF50',
  lightGreen: '#8BC34A',
  lime: '#CDDC39',
  yellow: '#FFEB3B',
  amber: '#FFC107',
  orange: '#FF9800',
  deepOrange: '#FF5722',
  brown: '#795548',
  blueGrey: '#607D8B',
  grey: '#9E9E9E',
  black: '#000000',
  white: '#FFFFFF',
}

export default {
  is: {
    local: isLocal,
  },
  ld,
  nav: markRaw(nav),
  keyMap,
  router: {},
  color,
}